import { useLocalStorage } from '@vueuse/core'
import { LOCAL_STORAGE_KEYS } from '@/constant'

const BOT_LIST = [
  'Googlebot',
  'Baiduspider',
  'bingbot',
  'Slurp',
  'Yandex',

  // 這三個是 google page speed
  // 因為 seo 人員都用 page speed insight 看 18 禁彈窗有沒有彈出，有彈出就說我們不對，所以我就讓他看到 google page speed insight 不會彈 18 禁...XD
  'Google Page Speed',
  'Mozilla/5.0 (Linux; Android 11; moto g power (2022)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36',
  'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
]
const isBot = () => {
  if (!navigator || !navigator.userAgent) {
    return false
  }

  const agent = navigator.userAgent
  return BOT_LIST.findIndex((bot) => agent.indexOf(bot) !== -1) !== -1
}

export function useAdultChecked() {
  const adultChecked = useLocalStorage(LOCAL_STORAGE_KEYS.ADULT_CHECKED, isBot())

  return { adultChecked }
}
